package com.beyondsoft.mcms.domain;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.EntityManager;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.TypedQuery;
import javax.validation.constraints.NotNull;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooJpaActiveRecord(finders = { "findFeeAmountsByBusinessTypeAndPositionType" })
public class FeeAmount {

    /**
     */
    @NotNull
    @ManyToOne
    private Item businessType;

    /**
     */
    @NotNull
    @ManyToOne
    private Item positionType;

    /**
     */
    @NotNull
    @ManyToOne
    private Item feePeriod;
    
    /**
     */
    @NotNull
    private BigDecimal payAmount;

    /**
     */
    private String updateBy;

    /**
     */
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(style = "M-")
    private Date updateDate;

    public static TypedQuery<FeeAmount> findFeeAmountsByBusinessTypeAndPositionType(Item businessType, Item positionType) {
        StringBuffer sql = new StringBuffer("SELECT o FROM FeeAmount AS o WHERE 1=1 ");
        if (businessType != null) {
            sql.append(" AND o.businessType = :businessType ");
        }
        if (positionType != null) {
            sql.append(" AND o.positionType = :positionType ");
        }
        sql.append(" ORDER BY o.positionType ");
        EntityManager em = FeeAmount.entityManager();
        TypedQuery<FeeAmount> q = em.createQuery(sql.toString(), FeeAmount.class);
        if (businessType != null) {
            q.setParameter("businessType", businessType);
        }
        if (positionType != null) {
            q.setParameter("positionType", positionType);
        }
        return q;
    }

    
}
